<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        累计消费次数：<span style="color: red;margin-right: 8px;">{{consumption.count}}</span>
      </el-form-item>

      <el-form-item label="预订范围" style="float: right;">
        <el-date-picker
          @change="getDataList()"
          v-model="dateRange"
          type="daterange"
          :clearable="true"
          value-format="yyyy-MM-dd"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border="" v-loading="dataListLoading" style="width: 100%;">
      <el-table-column prop="orderNo" header-align="center" align="center" width="180" label="订单号">
        <template slot-scope="scope">
          <el-link style="color: #409eff;cursor: pointer;" type="primary" @click="addOrUpdateHandle(scope.row.id)">
            {{scope.row.orderNo}}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column prop="sellerName" header-align="center" align="center" width="150" label="门店"></el-table-column>
      <el-table-column prop="roomType" header-align="center" align="center" width="120" label="房型"></el-table-column>
      <!--1未付款,2已付款，3取消,4完成,5已入住,6申请退款,7退款,8拒绝退款-->
      <el-table-column prop="totalCost" header-align="center" align="center" label="价格"></el-table-column>
      <el-table-column prop="status" header-align="center" align="center" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1" size="small">未付款</el-tag>
          <el-tag v-if="scope.row.status === 2" size="small">已付款</el-tag>
          <el-tag v-if="scope.row.status === 3" size="small">已取消</el-tag>
          <el-tag v-if="scope.row.status === 4" size="small">已完成</el-tag>
          <el-tag v-if="scope.row.status === 5" size="small">已入住</el-tag>
          <el-tag v-if="scope.row.status === 6" size="small">退款中</el-tag>
          <el-tag v-if="scope.row.status === 9" size="small">待入住</el-tag>
          <el-tag v-if="scope.row.status === 10" size="small">待评价</el-tag>
          <el-tag v-if="scope.row.status === 11" size="small">待确认</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="payMethod" header-align="center" width="120" align="center" label="支付方式">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.payMethod === null" size="small">到店支付</el-tag>
          <el-tag v-if="scope.row.payMethod === 'wx'" size="small">微信支付</el-tag>
          <el-tag v-if="scope.row.payMethod === 'balance'" size="small">余额支付</el-tag>
          <el-tag v-if="scope.row.payMethod === 'integral'" size="small">积分支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" width="160" label="预定时间"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[5, 10, 20]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>


    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "../../order/hotelorder-add-or-update";
export default {
  data() {
    return {
      dataForm: {
        status: null,
        key: '',
        userId: '',
        date: [],
        seller_id:''
      },
      consumption:{
        count:0,
        day:'',
        dayNum:''
      },
      dateRange: [],
      dateRange2: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 5,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      orderSettingVisible: false,
      orderNotificationVisible: false,
      setInterTime: ''
    };
  },
  components: {
    AddOrUpdate,
  },
  activated() {
    getDataList()
  },
  deactivated: function() {},
  methods: {
    //查看订单
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    //是否改变了值
    changeFlagFun() {},
    init(userId,sellerId,count) {
      this.$nextTick(() => {
        this.dataForm.userId = userId;
        this.consumption.count = count;
        this.dataForm.seller_id = sellerId;
        console.log(userId);
        this.getDataList();
      });
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let startTime = null;
      let endTime = null;
      let startTime2 = null;
      let endTime2 = null;
      if (!this.dateRange) this.dateRange = [];
      if (!this.dateRange2) this.dateRange2 = [];

      if (this.dateRange.length > 0) {
        startTime = this.dateRange[0];
      }
      if (this.dateRange.length > 1) {
        endTime = this.dateRange[1];
      }
      if (this.dateRange2.length > 0) {
        startTime2 = this.dateRange2[0];
      }
      if (this.dateRange2.length > 1) {
        endTime2 = this.dateRange2[1];
      }

      this.$http({
        url: this.$http.adornUrl('/hotel/hotelorder/list'),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          startDate: startTime,
          endDate: endTime,
          startDate2: startTime2,
          endDate2: endTime2,
          key: this.dataForm.key,
          userId: this.dataForm.userId,
          seller_id: this.dataForm.seller_id
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
          console.log(data);
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    }
  }
};
</script>
